﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using CommunitySystem.BO.EmpbasicBO;
using CommunitySystemModel;
using CommunitySystem.BO;
using NPOI.HSSF.UserModel;

namespace CommunitySystem.Web.Service
{
    // 注意: 使用“重构”菜单上的“重命名”命令，可以同时更改代码、svc 和配置文件中的类名“EmpBasicService”。
    public class EmpBasicService : IEmpBasicService
    {
        public ObservableCollection<BianZhiModel> GetBianZhi_JiBenModel(string OrgID)
        {
            return bo.GetBianZhi_JiBenModel(OrgID);
        }

        public bool UpdateBianZhi_JiBenModel(int id, string demo)
        {
            return bo.UpdateBianZhi_JiBenModel(id, demo);
        }
        public string GetDengLuJueSe(string loginName)
        {
            return bo.GetDengLuJueSe(loginName);
        }
        public ObservableCollection<DiaoDongModel> GetEmp_BasicInfoModelByCardNo(string cardno, int orgid)
        {
            return bo.GetEmp_BasicInfoModelByCardNo(cardno, orgid);
        }
        #region 基本信息

        private EmpbasicBO bo = new EmpbasicBO();

        public string GetDengLuOrg(string loginName)
        {
            return bo.GetDengLuOrg(loginName);
        }

        public int GetEmp_BasicInfoCounts(string OrgID, string EmpID, string name, string orgtype, string empstatus, string highQueryCondition, bool keji, bool chuji)
        {
            return bo.GetEmp_BasicInfoCounts(OrgID, EmpID, name, orgtype, empstatus, highQueryCondition, keji, chuji);
        }
        public ObservableCollection<CommunitySystemModel.Emp_BasicInfoModel> GetEmp_BasicInfo(string OrgID, string EmpID, string name, string orgname, int start,
            int end, string empstatus, string highQueryCondition, bool? keji, bool? chuji)
        {
            //需要把组织机构ID传过来，这样才能找各个单位的人
            return bo.GetEmp_BasicInfos(OrgID, EmpID, name, orgname, start, end, empstatus, highQueryCondition, keji, chuji);
        }
        public int AddEmp_BasicInfo(CommunitySystemModel.Emp_BasicInfoModel item)
        {
            return bo.AddEmp_BasicInfo(item);
        }

        public bool UpdateEmp_BasicInfo(CommunitySystemModel.Emp_BasicInfoModel item)
        {
            return bo.UpdateEmp_BasicInfo(item);
        }

        public bool DeleteEmp_BasicInfo(string ID)
        {
            return bo.DeteleEmp_BasicInfo(ID);
        }

        public ObservableCollection<Emp_BasicInfoModel> GetDanWeiEmp_BasicInfos(string OrgID, string empstatus, bool keji, bool chuji)
        {
            return bo.GetDanWeiEmp_BasicInfos(OrgID, empstatus,keji,chuji);
        }
        #endregion

        #region 职务信息

        public ObservableCollection<Emp_Duty> GetEmp_Dutys(string EmpID, int ID)
        {
            return bo.GetEmp_Dutys(EmpID, ID);
        }

        public ObservableCollection<Emp_Duty> GetEmp_DutysJobStatus(string EmpID, int ID)
        {
            return bo.GetEmp_DutysJobStatus(EmpID, ID);
        }
        public bool AddEmp_Duty(Emp_Duty item)
        {
            if (bo.AddEmp_Duty(item))
            {
                string sql = string.Format(@"update Emp_BasicInfo 
set PositionName=(select top 1 DutyName from Emp_Duty where EmpbasicID={0} and JobStatus='在任' order by  OKDate desc)
where ID={0}", item.EmpBasicID);
                AccessHelper.GetInstance().ExecuteNonQuery(sql);
                return true;
            }
            else return false;
        }


        public bool UpdateEmp_Duty(Emp_Duty item)
        {
            if (bo.UpdateEmp_Duty(item))
            {
                string sql = string.Format(@"update Emp_BasicInfo 
set PositionName=(select top 1 DutyName from Emp_Duty where EmpbasicID={0} and JobStatus='在任' order by  OKDate desc)
where ID={0}", item.EmpBasicID);
                AccessHelper.GetInstance().ExecuteNonQuery(sql);
                return true;
            }
            return false;
        }


        public bool DeteleEmp_Duty(int ID)
        {

            return bo.DeteleEmp_Duty(ID);
        }

        #endregion

        #region 简历信息

        public ObservableCollection<Emp_ResumeModel> GetEmp_Resume(string EmpID, int ID)
        {
            return bo.GetEmp_Resume(EmpID, ID);
        }

        public ObservableCollection<Emp_ResumeModel> GetEmp_ResumeBYJL(string EmpID, int ID)
        {
            return bo.GetEmp_ResumeBYJL(EmpID, ID);
        }
        public bool AddEmp_Resume(Emp_ResumeModel item)
        {
            return bo.AddEmp_Resume(item);
        }


        public bool UpdateEmp_ResumeModel(Emp_ResumeModel item)
        {
            return bo.UpdateEmp_ResumeModel(item);
        }


        public bool DeteleEmp_ResumeModel(int ID)
        {
            return bo.DeteleEmp_ResumeModel(ID);
        }

        #endregion

        #region 学历信息

        public ObservableCollection<Emp_EducationModel> GetEmp_EducationModel(string EmpID, int ID)
        {
            return bo.GetEmp_EducationModel(EmpID, ID);
        }
        public ObservableCollection<Emp_EducationModel> GetEmp_EducationModelByJL(string EmpID, int ID)
        {
            return bo.GetEmp_EducationModelByJL(EmpID, ID);
        }

        public bool AddEmp_EducationModel(Emp_EducationModel item)
        {
            return bo.AddEmp_EducationModel(item);
        }


        public bool UpdateEmp_EducationModel(Emp_EducationModel item)
        {
            return bo.UpdateEmp_EducationModel(item);
        }


        public bool DeteleEmp_EducationModel(int ID)
        {
            return bo.DeteleEmp_EducationModel(ID);
        }

        #endregion

        #region 学位信息

        public ObservableCollection<Emp_DegreeModel> GetEmp_DegreeModel(string EmpID, int ID)
        {
            return bo.GetEmp_DegreeModel(EmpID, ID);
        }
        public ObservableCollection<Emp_DegreeModel> GetEmp_DegreeModelBYJL(string EmpID, int ID)
        {
            return bo.GetEmp_DegreeModelBYJL(EmpID, ID);
        }

        public bool AddEmp_DegreeModel(Emp_DegreeModel item)
        {
            return bo.AddEmp_DegreeModel(item);
        }


        public bool UpdateEmp_DegreeModel(Emp_DegreeModel item)
        {
            return bo.UpdateEmp_DegreeModel(item);
        }


        public bool DeteleEmp_DegreeModel(int ID)
        {
            return bo.DeteleEmp_DegreeModel(ID);
        }

        #endregion

        #region 考核信息

        public ObservableCollection<Emp_AssessmentModel> GetEmp_AssessmentModel(string EmpID, int ID)
        {
            return bo.GetEmp_AssessmentModel(EmpID, ID);
        }

        public ObservableCollection<Emp_AssessmentModel> GetEmp_AssessmentModelBySND(string EmpID, int ID)
        {
            return bo.GetEmp_AssessmentModelBySND(EmpID, ID);
        }
        public bool AddEmp_AssessmentModel(Emp_AssessmentModel item)
        {
            return bo.AddEmp_AssessmentModel(item);
        }


        public bool UpdateEmp_AssessmentModel(Emp_AssessmentModel item)
        {
            return bo.UpdateEmp_AssessmentModel(item);
        }


        public bool DeteleEmp_AssessmentModel(int ID)
        {
            return bo.DeteleEmp_AssessmentModel(ID);
        }

        #endregion

        #region 奖惩信息

        public ObservableCollection<Emp_RewardInfoModel> GetEmp_RewardInfoModel(string EmpID, int ID)
        {
            return bo.GetEmp_RewardInfoModel(EmpID, ID);
        }
        public ObservableCollection<Emp_RewardInfoModel> GetEmp_RewardInfoModelByJL(string EmpID, int ID)
        {
            return bo.GetEmp_RewardInfoModelByJL(EmpID, ID);
        }
        

        public bool AddEmp_RewardInfoModel(Emp_RewardInfoModel item)
        {
            return bo.AddEmp_RewardInfoModel(item);
        }


        public bool UpdateEmp_RewardInfoModel(Emp_RewardInfoModel item)
        {
            return bo.UpdateEmp_RewardInfoModel(item);
        }


        public bool DeteleEmp_RewardInfoModel(int ID)
        {
            return bo.DeteleEmp_RewardInfoModel(ID);
        }

        #endregion

        #region 处分信息

        public ObservableCollection<Emp_PunishmentModel> GetEmp_PunishmentModel(string EmpID, int ID)
        {
            return bo.GetEmp_PunishmentModel(EmpID, ID);
        }
        public ObservableCollection<Emp_PunishmentModel> GetEmp_PunishmentModelByJL(string EmpID, int ID)
        {
            return bo.GetEmp_PunishmentModelByJL(EmpID, ID);
        }

        public bool AddEmp_PunishmentModel(Emp_PunishmentModel item)
        {
            return bo.AddEmp_PunishmentModel(item);
        }


        public bool UpdateEmp_PunishmentModel(Emp_PunishmentModel item)
        {
            return bo.UpdateEmp_PunishmentModel(item);
        }


        public bool DeteleEmp_PunishmentModel(int ID)
        {
            return bo.DeteleEmp_PunishmentModel(ID);
        }

        #endregion

        #region 家庭信息

        public ObservableCollection<Emp_FamilyRelationModel> GetEmp_FamilyRelationModel(string EmpID, int ID)
        {
            return bo.GetEmp_FamilyRelationModel(EmpID, ID);
        }
        public ObservableCollection<Emp_FamilyRelationModel> GetEmp_FamilyRelationModelByJL(string EmpID, int ID)
        {
            return bo.GetEmp_FamilyRelationModelByJL(EmpID, ID);
        }


        public bool AddEmp_FamilyRelationModel(Emp_FamilyRelationModel item)
        {
            return bo.AddEmp_FamilyRelationModel(item);
        }


        public bool UpdateEmp_FamilyRelationModel(Emp_FamilyRelationModel item)
        {
            return bo.UpdateEmp_FamilyRelationModel(item);
        }


        public bool DeteleEmp_FamilyRelationModel(int ID)
        {
            return bo.DeteleEmp_FamilyRelationModel(ID);
        }

        #endregion


        #region 日志管理
        public ObservableCollection<System_MarkManageModel> GetSystemMark(string dengluren, int start, int end, string caozuoren, string caozuoriqi)
        {
            return bo.GetSystemMark(dengluren, start, end, caozuoren, caozuoriqi);
        }

        public bool AddSystem_Mark(string ZiJi, string OldContent, string NewContent, int EmpID, string CaoZuoFangShi, string ZiDuan, string DengLuRen)
        {
            return bo.AddSystem_Mark(ZiJi, OldContent, NewContent, EmpID, CaoZuoFangShi, ZiDuan, DengLuRen);
        }

        public bool UpdateSystem_Mark(System_MarkManageModel item)
        {
            return bo.UpdateSystem_Mark(item);
        }
        #endregion

        #region 组织机构管理
        public ObservableCollection<OrgForHRModel> GetOrgForHRModel(int OrgID)
        {
            return bo.GetOrgForHRModel(OrgID);
        }

        public ObservableCollection<OrgForHRModel> GetOrgForHRModelbyIDs(string OrgID)
        {
            return bo.GetOrgForHRModelbyIDs(OrgID);
        }

        public bool AddOrgForHRModel(OrgForHRModel item)
        {
            return bo.AddOrgForHRModel(item);
        }

        public bool UpdateOrgForHRModel(OrgForHRModel item)
        {
            return bo.UpdateOrgForHRModel(item);
        }

        public bool DeteleOrgForHRModel(int ID)
        {
            return bo.DeteleOrgForHRModel(ID);
        }
        #endregion

        #region 编制管理
        public ObservableCollection<BianZhiModel> GetBianZhiModel(string OrgID, int ID)
        {
            return bo.GetBianZhiModel(OrgID, ID);
        }

        public bool AddBianZhiModel(BianZhiModel item)
        {
            return bo.AddBianZhiModel(item);
        }

        public bool UpdateBianZhiModel(BianZhiModel item)
        {
            return bo.UpdateBianZhiModel(item);
        }
        public ObservableCollection<BianZhiModel> GetBianZhiModelShiYou(int OrgID)
        {
            return bo.GetBianZhiModelShiYou(OrgID);
        }

        public bool DeleteBianZhiModel(BianZhiModel item)
        {
            return bo.DeleteBianZhiModel(item);
        }

        public ObservableCollection<BianZhiModel> GetBianZhiModelForTongChou(int OrgID)
        {
            return bo.GetBianZhiModelForTongChou(OrgID);
        }

        public bool TCXZ(string type, int shu, string ids, string name)
        {
            return bo.TCXZ(type, shu, ids, name);
        }

        public bool QuXiaoTongChou(string type, int orgid)
        {
            return bo.QuXiaoTongChou(type, orgid);
        }

        public bool CanTCXZ(string type, string ids)
        {
            return bo.CanTCXZ(type, ids);
        }
        #endregion

        private ExportPersonnelInfoBO ebo = null;
        public FileTransferStream GetPersonnelInfoExcel(int id, string UserName)
        {
            if (ebo == null || ebo._id != id)
                ebo = new ExportPersonnelInfoBO(id);
            return ebo.GetExcelFile(id, UserName);
        }

        public bool CanDaoRuAll(ObservableCollection<Emp_BasicInfoModel> InEmpBasicModels)
        {
            return bo.CanDaoRuAll(InEmpBasicModels);
        }

        public bool ShanChuDaoRuAll(ObservableCollection<Emp_BasicInfoModel> InEmpBasicModels)
        {
            return bo.ShanChuDaoRuAll(InEmpBasicModels);
        }

        public bool DaoRuAll(ObservableCollection<Emp_BasicInfoModel> InEmpBasicModels,
                      ObservableCollection<Emp_EducationModel> InEmpEducation,
                      ObservableCollection<Emp_DegreeModel> InEmpDegree,
                      ObservableCollection<Emp_ResumeModel> InEmpResume,
                      ObservableCollection<Emp_Duty> InEmpDuty, ObservableCollection<Emp_RewardInfoModel> InEmpReward,
                      ObservableCollection<Emp_PunishmentModel> InEmpPunish,
                      ObservableCollection<Emp_AssessmentModel> InEmpAssenssment,
                      ObservableCollection<Emp_FamilyRelationModel> InEmpFamily)
        {
            return bo.DaoRuAll(InEmpBasicModels, InEmpEducation, InEmpDegree, InEmpResume, InEmpDuty, InEmpReward,
                        InEmpPunish, InEmpAssenssment, InEmpFamily);
        }

        public PeiZhiLieModel GetLieByUserID(int userID)
        {
            return bo.GetLieByUserID(userID);
        }

        public bool UpdateLie(PeiZhiLieModel item)
        {
            return bo.UpdateLie(item);
        }

        private ExportPersonnelInfoBO exportBo = null;
        public string ExportPersonnelInfoPosition(int empid, int position)
        {
            if (exportBo == null)
                exportBo = new ExportPersonnelInfoBO(empid);
            return exportBo.ExportPersonnelInfoPosition(empid, position);
        }

        public int GetSystemMarkCounts(string dengluren, string caozuoren, string caozuoriqi)
        {
            return bo.GetSystemMarkCounts(dengluren, caozuoren, caozuoriqi);
        }

        public int GetCheGaiCounts(string caozuoren, string caozuoriqi, string endcaozuoriqi, string orgid, string status, int keyid, string dengjibiandong)
        {
            return bo.GetCheGaiCounts(caozuoren, caozuoriqi, endcaozuoriqi, orgid, status, keyid, dengjibiandong);
        }

        public ObservableCollection<CheGaiModel> GetCheGai(string caozuoren, string caozuoriqi, string endcaozuoriqi, string orgid, string status,
                                                    int start, int end, int keyid, string dengjibiandong)
        {
            return bo.GetCheGai(caozuoren, caozuoriqi, endcaozuoriqi, orgid, status,
                                start, end, keyid, dengjibiandong);
        }

        public CheGaiModel GetOneCheGai(int id)
        {
            return bo.GetOneCheGai(id);
        }

        public bool UpdateCheGai(CheGaiModel item)
        {
            return bo.UpdateCheGai(item);
        }

        public void InsertCheGai(int EmpID, string Type, string dengjibiandongtype)
        {
            bo.InsertCheGai(EmpID, Type, dengjibiandongtype);
        }

        public bool UpdateCheGaiAll(ObservableCollection<CheGaiModel> item)
        {
            return bo.UpdateCheGaiAll(item);
        }

        public ObservableCollection<string> GetKeyIDs(string caozuoriqi, string endcaozuoriqi, string orgid)
        {
            return bo.GetKeyIDs(caozuoriqi, endcaozuoriqi, orgid);
        }

        public ObservableCollection<ZhiJiModel> GetZhiJiModel(int ID)
        {
            return bo.GetZhiJiModel(ID);
        }
        public bool AddZhiJiModel(ZhiJiModel item)
        {
            return bo.AddZhiJiModel(item);
        }
        public bool UpdateZhiJiModel(ZhiJiModel item)
        {
            return bo.UpdateZhiJiModel(item);
        }

        //public FileTransferStream GetExcelFile(ObservableCollection<CheGaiModel> models)
        //{
        //    return bo.GetExcelFile(models);
        //}

        public bool DeteleCheGai(int ID)
        {
            return bo.DeteleCheGai(ID);
        }


        public ObservableCollection<BianZhiModel> GetBianZhiDetailModel(string OrgID, string jigoumingcheng)
        {
            return bo.GetBianZhiDetailModel(OrgID, jigoumingcheng);
        }

        public ObservableCollection<BianZhiModel> GetBianZhiDetail_JieYongModel(string OrgID, string type)
        {
            return bo.GetBianZhiDetail_JieYongModel(OrgID, type);
        }


        public void UpdateBianZhiDetail_JieYongModel(string BianZhiID, string type, BianZhiModel model, int isguoduxing, string guoduxing, bool isnew)
        {
            bo.UpdateBianZhiDetail_JieYongModel(BianZhiID, type, model, isguoduxing, guoduxing, isnew);
        }

        public ObservableCollection<BianZhiModel> GetBianZhiDetail_YiJieYongModel(int ID, string type, int zhengfu)
        {
            return bo.GetBianZhiDetail_YiJieYongModel(ID, type, zhengfu);
        }

        public ObservableCollection<Emp_BasicInfoModel> GetEmp_BasicInfoModelByKeShi(int orgid, string type, string keshiname, string zairenjianren, string empid)
        {
            return bo.GetEmp_BasicInfoModelByKeShi(orgid, type, keshiname, zairenjianren, empid);
        }

        public bool UpdateChaoZhiQingKuang(int id, string demo)
        {
            return bo.UpdateChaoZhiQingKuang(id, demo);
        }

        public bool InsertChaoZhi(int bianzhiid, string type, string guoduxingzhishu, string bianzhiname)
        {
            return bo.InsertChaoZhi(bianzhiid, type, guoduxingzhishu, bianzhiname);
        }

        public string GetChaoZhiShu(int bianzhiid, string type)
        {
            return bo.GetChaoZhiShu(bianzhiid, type);
        }

        public ObservableCollection<Emp_BasicInfoModel> GetEmpIds(int bianzhiid, string type, int isguoduxing)
        {
            return bo.GetEmpIds(bianzhiid, type, isguoduxing);
        }

        public ObservableCollection<Emp_BasicInfoModel> GetEmpIds_guodu(int bianzhiid, string type, int isguoduxing)
        {
            return bo.GetEmpIds(bianzhiid, type, isguoduxing);
        }

        public bool UpdateBianZhiAnPaiRenYuan(ObservableCollection<int> empid, int bianzhijieyongid, string jieyongorguodu, string type)
        {
            return bo.UpdateBianZhiAnPaiRenYuan(empid, bianzhijieyongid, jieyongorguodu, type);
        }


        public bool CanTuiHuanZhiShu(int bianzhijieyongid)
        {
            return bo.CanTuiHuanZhiShu(bianzhijieyongid);
        }

        public bool TuiHuanZhiShu(int bianzhijieyongid, int empid)
        {
            return bo.TuiHuanZhiShu(bianzhijieyongid, empid);
        }

        public byte[] ExportDW(ObservableCollection<BianZhiModel> tjfx)
        {
            HSSFWorkbook workbook = bo.ExportExcelDW(tjfx.ToList());
            return new EmpbasicBO().ExcelToBytes(workbook);

        }


        public byte[] ExportDW1(string orgid)
        {
            ObservableCollection<BianZhiModel> BianZhiModels = bo.GetBianZhiDetailModel(orgid, "");
            if (BianZhiModels != null)
            {
                string zhurenkeyong = "";
                int i1 =
                    Convert.ToInt32(
                        !string.IsNullOrEmpty(BianZhiModels.OrderBy(p => p.FuKeLingDao).FirstOrDefault().FuKeLingDao)
                            ? BianZhiModels.OrderBy(p => p.FuKeLingDao).FirstOrDefault().FuKeLingDao
                            : "0");
                int i2 =
                    Convert.ToInt32(
                        !string.IsNullOrEmpty(
                            BianZhiModels.OrderByDescending(p => p.zhurenshiyou).FirstOrDefault().zhurenshiyou)
                            ? BianZhiModels.OrderByDescending(p => p.zhurenshiyou).FirstOrDefault().zhurenshiyou
                            : "0");

                int i3 = 0;
                foreach (BianZhiModel b in BianZhiModels)
                {
                    if (!string.IsNullOrEmpty(b.ZhuRenJieYongQingKuang) && b.ZhuRenJieYongQingKuang != "无")
                    {
                        if (Math.Abs(Convert.ToInt32(b.ZhuRenJieYongQingKuang)) > i3)
                            i3 = Convert.ToInt32(b.ZhuRenJieYongQingKuang);
                    }
                }
                int i4 =
                    Convert.ToInt32(
                        BianZhiModels.OrderByDescending(p => p.ZhuRenChaoZhiQingKuang).FirstOrDefault().
                            ZhuRenChaoZhiQingKuang == "无"
                            ? "0"
                            : BianZhiModels.OrderByDescending(p => p.ZhuRenChaoZhiQingKuang).FirstOrDefault().
                                  ZhuRenChaoZhiQingKuang);
                zhurenkeyong = "统筹：" + (i1 - i2 + i3 + i4).ToString();

                string fuzhurenkeyong = "";
                int f1 =
                    Convert.ToInt32(
                        !string.IsNullOrEmpty(BianZhiModels.OrderBy(p => p.FuKeFeiLingDao).FirstOrDefault().FuKeFeiLingDao)
                            ? BianZhiModels.OrderBy(p => p.FuKeFeiLingDao).FirstOrDefault().FuKeFeiLingDao
                            : "0");
                int f2 =
                    Convert.ToInt32(
                        !string.IsNullOrEmpty(
                            BianZhiModels.OrderByDescending(p => p.fuzhurenshiyou).FirstOrDefault().fuzhurenshiyou)
                            ? BianZhiModels.OrderByDescending(p => p.fuzhurenshiyou).FirstOrDefault().fuzhurenshiyou
                            : "0");

                int f3 = 0;
                foreach (BianZhiModel b in BianZhiModels)
                {
                    if (!string.IsNullOrEmpty(b.FuZhuRenJieYongQingKuang) && b.FuZhuRenJieYongQingKuang != "无")
                    {
                        if (Math.Abs(Convert.ToInt32(b.FuZhuRenJieYongQingKuang)) > f3)
                            f3 = Convert.ToInt32(b.FuZhuRenJieYongQingKuang);
                    }
                }
                int f4 =
                    Convert.ToInt32(
                        BianZhiModels.OrderByDescending(p => p.FuZhuRenChaoZhiQingKuang).FirstOrDefault().
                            FuZhuRenChaoZhiQingKuang == "无"
                            ? "0"
                            : BianZhiModels.OrderByDescending(p => p.FuZhuRenChaoZhiQingKuang).FirstOrDefault().
                                  FuZhuRenChaoZhiQingKuang);
                fuzhurenkeyong = "统筹：" + (f1 - f2 + f3 + f4).ToString();

                if (BianZhiModels.Where(p => p.ZhengKeLingDaoTC == true).Count() > 0)
                {
                    foreach (BianZhiModel i in BianZhiModels.Where(p => p.ZhengKeLingDaoTC == true))
                    {
                        int zhiwhu = !string.IsNullOrEmpty(i.ZhengKeLingDao) ? Convert.ToInt32(i.ZhengKeLingDao) : 0;
                        int renshu = BianZhiModels.Where(p => p.ZhengKeLingDaoTC == true).Sum(
                            p => !string.IsNullOrEmpty(p.zhengkeshiyou) ? Convert.ToInt32(p.zhengkeshiyou) : 0);
                        int jieyong = BianZhiModels.Where(p => p.ZhengKeLingDaoTC == true).Sum(
                            p =>
                            p.ZhengKeJieYongQingKuang != "无" ? Convert.ToInt32(p.ZhengKeJieYongQingKuang) : 0);
                        int chaozhi = BianZhiModels.Where(p => p.ZhengKeLingDaoTC == true).Sum(
                            p =>
                            p.ZhengKeChaoZhiQingKuang != "无" ? Convert.ToInt32(p.ZhengKeChaoZhiQingKuang) : 0);

                        i.ZhengKeShiJi =
                            (zhiwhu - renshu + jieyong + chaozhi)
                                .ToString();
                        //i.ZhengKeShiJi =
                        //    (Convert.ToInt32(
                        //        BianZhiModels.Where(p => p.ZhengKeLingDaoTC == true).OrderBy(p => p.ZhengKeShiJi).
                        //            FirstOrDefault().ZhengKeShiJi) +
                        //     BianZhiModels.Sum(
                        //         p => p.ZhengKeJieYongQingKuang != "无" ? Convert.ToInt32(p.ZhengKeJieYongQingKuang) : 0) +
                        //     BianZhiModels.Sum(
                        //         p => p.ZhengKeChaoZhiQingKuang != "无" ? Convert.ToInt32(p.ZhengKeChaoZhiQingKuang) : 0))
                        //        .ToString();
                    }
                }

                if (BianZhiModels.Where(p => p.ZhengKeFeiLingDaoTC == true).Count() > 0)
                {
                    //foreach (BianZhiModel i in BianZhiModels.Where(p => p.ZhengKeFeiLingDaoTC == true))
                    //{
                    //    i.FuKeShiJi =
                    //        BianZhiModels.Where(p => p.ZhengKeFeiLingDaoTC == true).OrderBy(p => p.FuKeShiJi).
                    //            FirstOrDefault().FuKeShiJi;
                    //}
                    foreach (BianZhiModel i in BianZhiModels.Where(p => p.ZhengKeFeiLingDaoTC == true))
                    {
                        i.FuKeShiJi =
                            (Convert.ToInt32(
                                BianZhiModels.Where(p => p.ZhengKeFeiLingDaoTC == true).OrderBy(p => p.FuKeShiJi).
                                    FirstOrDefault().FuKeShiJi) +
                             BianZhiModels.Sum(
                                 p => p.FuKeJieYongQingKuang != "无" ? Convert.ToInt32(p.FuKeJieYongQingKuang) : 0) +
                             BianZhiModels.Sum(
                                 p => p.FuKeChaoZhiQingKuang != "无" ? Convert.ToInt32(p.FuKeChaoZhiQingKuang) : 0))
                                .ToString();

                        int zhiwhu = !string.IsNullOrEmpty(i.ZhengKeFeiLingDao) ? Convert.ToInt32(i.ZhengKeFeiLingDao) : 0;
                        int renshu = BianZhiModels.Where(p => p.ZhengKeFeiLingDaoTC == true).Sum(
                            p => !string.IsNullOrEmpty(p.fukeshiyou) ? Convert.ToInt32(p.fukeshiyou) : 0);
                        int jieyong = BianZhiModels.Where(p => p.ZhengKeFeiLingDaoTC == true).Sum(
                            p =>
                            p.FuKeJieYongQingKuang != "无" ? Convert.ToInt32(p.FuKeJieYongQingKuang) : 0);
                        int chaozhi = BianZhiModels.Where(p => p.ZhengKeFeiLingDaoTC == true).Sum(
                            p =>
                            p.FuKeChaoZhiQingKuang != "无" ? Convert.ToInt32(p.FuKeChaoZhiQingKuang) : 0);

                        i.ZhengKeShiJi =
                            (zhiwhu - renshu + jieyong + chaozhi)
                                .ToString();
                    }
                }
                foreach (BianZhiModel i in BianZhiModels)
                {
                    i.ZhuRenShiJi = zhurenkeyong;
                    i.FuZhuRenShiJi = fuzhurenkeyong;
                    
                    
                }
            }
            HSSFWorkbook workbook = bo.ExportExcelDW(BianZhiModels.ToList());
            return new EmpbasicBO().ExcelToBytes(workbook);
        }

        #region IEmpBasicService 成员


        public ObservableCollection<Emp_BasicInfoModel> GetEmp_BasicInfoByCon(string con)
        {
            return bo.GetEmp_BasicInfoByCon(con);
        }

        #endregion

        #region IEmpBasicService 表单管理
        public ObservableCollection<Emp_BDGLModel> GetSYQMKH(string con, int index, int pagesize)
        {
            return Emp_BDGLBO.GetSYQMKH(con, index, pagesize);
        }

        public bool SYQMKH_SB(Emp_BDGLModel model)
        {
            return Emp_BDGLBO.SYQMKH_SB(model);
        }
        public int GetSYQMKHCount(string con)
        {
            return Emp_BDGLBO.GetSYQMKHCount(con);
        }
        #endregion

        #region IEmpBasicService 成员


        public ObservableCollection<Emp_BasicInfoModel> GetEmp(string con)
        {
           return bo.GetEmp(con);
        }

        #endregion
    }
}
